package com.yanzhu.api;

import com.yanzhu.bean.ResponseBean;
import com.yanzhu.service.MessageService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: 方炎柱
 * @Description:
 * @Date: Created in 11:35 2018/2/2
 * @Modified:
 */
@AllArgsConstructor
@RestController
public class MessageAPI {

    private final MessageService messageService;

    @RequestMapping(value="/queryMessageList")
    public ResponseBean queryMessageList(HttpServletRequest request){
        String uid = request.getParameter("uid");
        if(uid == null || uid.equals(""))
            return ResponseBean.fail("缺少用户ID参数!");

        String page = request.getParameter("page");
        if(page == null || page.equals(""))
            return ResponseBean.fail("缺少页数参数!");

        String size = request.getParameter("size");
        if(size == null || size.equals(""))
            return ResponseBean.fail("缺少页数大小参数!");

        return ResponseBean.ok(messageService.queryMessageList(Long.parseLong(uid), Integer.parseInt(page), Integer.parseInt(size)));
    }
}
